package com.example.onlinemusic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.onlinemusic.common.R;
import com.example.onlinemusic.mapper.CommentMapper;
import com.example.onlinemusic.model.domain.Comment;
import com.example.onlinemusic.model.request.CommentRequest;
import com.example.onlinemusic.service.CommentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {
    @Autowired
    CommentMapper commentMapper;

    @Override
    public R commentListOfSongListId(int songListId) {
        return R.success("查询成功", commentMapper.selectCommentListBySongListId(songListId));
    }

    @Override
    public R addComment(CommentRequest commentRequest) {
        Comment comment = new Comment();
        BeanUtils.copyProperties(commentRequest, comment);
        // 设置表其他的字段内容
        comment.setType(commentRequest.getNowType());
        comment.setUp(0);
        comment.setCreateTime(new Date());
        int i = commentMapper.insert(comment);
        if (i > 0) {
            return R.success("评论成功");
        } else {
            return R.success("评论失败");
        }
    }
}
